//
//  XGOfflineDownloadTableViewCell.swift
//  TodayNews
//
//  Created by monkey on 2020/2/10.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit

class XGOfflineDownloadTableViewCell: UITableViewCell,XGRegisterReusableViewProtocol
{
    /// 新闻分类数据模型
    var newsCategoryModel: XGNewsCategoryModel? {
        didSet {
            titleLabel.text = newsCategoryModel?.name
            checkedButton.isSelected = newsCategoryModel?.isSelected ?? false
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?)
    {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        setUpUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 标题按钮
    private lazy var titleLabel: UILabel = UILabel(text: "测试", textColor: UIColor.darkGray, fontSize: 20, textAlignment: .left)
    /// 选择标记按钮
    private lazy var checkedButton: UIButton = {
        let button = UIButton(type: .custom)
        button.theme_setImage("images.offlineDownload_button_normal", forState: .normal)
        button.theme_setImage("images.offlineDownload_button_selected", forState: .selected)
        button.sizeToFit()
        button.isUserInteractionEnabled = false
        return button
    }()
}

private extension XGOfflineDownloadTableViewCell
{
    /// 设置界面
    func setUpUI() -> Void
    {
        theme_backgroundColor = "colors.cell_background"
        titleLabel.theme_textColor = "colors.cell_title"
        
        contentView.addSubview(titleLabel)
        contentView.addSubview(checkedButton)
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(20)
        }
        
        checkedButton.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-20)
        }
    }
}
